package com.xwj.xuthread.starter.configuration;

import com.alibaba.cloud.nacos.NacosConfigManager;
import com.xwj.xuthread.spring.core.ThreadPoolManager;
import com.xwj.xuthread.spring.enable.MarkerConfiguration;
import com.xwj.xuthread.spring.nacos.NacosConfigListener;
import com.xwj.xuthread.spring.nacos.ThreadPoolNacosConfig;
import com.xwj.xuthread.spring.support.XuThreadBeanPostProcessor;
import com.xwj.xuthread.spring.task.ThreadPoolMonitor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.scheduling.annotation.EnableScheduling;

/**
 * @Description TODO
 * @Author xwj
 * @Date 2025/8/24
 */
@Configuration
@ConditionalOnBean(MarkerConfiguration.Marker.class)
@ConditionalOnProperty(prefix = "xuthread", value = "enable", matchIfMissing = true, havingValue = "true")
@EnableScheduling
public class XuThreadPoolAutoConfiguration {

//    @Bean
//    public ThreadPoolManager threadPoolManager(){
//        return new ThreadPoolManager();
//    }
//    @Bean
//    public ThreadPoolNacosConfig threadPoolNacosConfig(){
//        return new ThreadPoolNacosConfig();
//    }
    @Bean
    @DependsOn("threadPoolNacosConfig")
    public NacosConfigListener nacosConfigListener(NacosConfigManager nacosConfigManager){
        return new NacosConfigListener(nacosConfigManager.getConfigService());
    }

    @Bean
    @DependsOn("threadPoolNacosConfig")
    public XuThreadBeanPostProcessor xuThreadBeanPostProcessor(ThreadPoolNacosConfig threadPoolNacosConfig){
        return new XuThreadBeanPostProcessor(threadPoolNacosConfig);
    }

    @Bean
    public ThreadPoolMonitor threadPoolMonitor(){
        return new ThreadPoolMonitor();
    }
}